snapshot: Add gsk_snapshot_append_conic_gradient()
authorBenjamin Otte <otte@redhat.com>
Thu, 3 Dec 2020 00:15:53 +0000 (01:15 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 3 Dec 2020 00:15:53 +0000 (01:15 +0100)
docs/reference/gtk/gtk4-sections.txt
gtk/gtksnapshot.c
gtk/gtksnapshot.h

index c6e8f87a58ab197ac7296260a9888792fb39c41f..a13864c7d102aa549b8a9af470f45050e38478e4 100644 (file)
@@ -4329,6 +4329,7 @@ gtk_snapshot_append_color
 gtk_snapshot_append_layout
 gtk_snapshot_append_linear_gradient
 gtk_snapshot_append_repeating_linear_gradient
+gtk_snapshot_append_conic_gradient
 gtk_snapshot_append_border
 gtk_snapshot_append_inset_shadow
 gtk_snapshot_append_outset_shadow
index 40122f633892972c4cf3f08a8bdb80befc80eb6b..7c5c74484237ef16cd91664b408152d3929289eb 100644 (file)
@@ -2249,6 +2249,66 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot            *snapshot,
   gtk_snapshot_append_node_internal (snapshot, node);
 }
 
+/**
+ * gtk_snapshot_append_conic_gradient:
+ * @snapshot: a #GtkSnapshot
+ * @bounds: the rectangle to render the gradient into
+ * @center: the center point of the conic gradient
+ * @rotation: the clockwise rotation in degrees of the starting angle. 0 means the
+ *     starting angle is the top.
+ * @stops: (array length=n_stops): a pointer to an array of #GskColorStop defining the gradient
+ * @n_stops: the number of elements in @stops
+ *
+ * Appends a conic gradient node with the given stops to @snapshot.
+ */
+void
+gtk_snapshot_append_conic_gradient (GtkSnapshot            *snapshot,
+                                    const graphene_rect_t  *bounds,
+                                    const graphene_point_t *center,
+                                    float                   rotation,
+                                    const GskColorStop     *stops,
+                                    gsize                   n_stops)
+{
+  GskRenderNode *node;
+  graphene_rect_t real_bounds;
+  float dx, dy;
+  const GdkRGBA *first_color;
+  gboolean need_gradient = FALSE;
+  int i;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (center != NULL);
+  g_return_if_fail (stops != NULL);
+  g_return_if_fail (n_stops > 1);
+
+  gtk_snapshot_ensure_translate (snapshot, &dx, &dy);
+  graphene_rect_offset_r (bounds, dx, dy, &real_bounds);
+
+  first_color = &stops[0].color;
+  for (i = 0; i < n_stops; i ++)
+    {
+      if (!gdk_rgba_equal (first_color, &stops[i].color))
+        {
+          need_gradient = TRUE;
+          break;
+        }
+    }
+
+  if (need_gradient)
+    node = gsk_conic_gradient_node_new (&real_bounds,
+                                        &GRAPHENE_POINT_INIT(
+                                          center->x + dx,
+                                          center->y + dy
+                                        ),
+                                        rotation,
+                                        stops,
+                                        n_stops);
+  else
+    node = gsk_color_node_new (first_color, &real_bounds);
+
+  gtk_snapshot_append_node_internal (snapshot, node);
+}
+
 /**
  * gtk_snapshot_append_radial_gradient:
  * @snapshot: a #GtkSnapshot
index 19e0045b1776442091145b4838b2318b379c17e2..6125e44eccd7a10819572e98665c429357dbe31e 100644 (file)
@@ -191,6 +191,13 @@ void            gtk_snapshot_append_repeating_radial_gradient (GtkSnapshot
                                                                const GskColorStop     *stops,
                                                                gsize                   n_stops);
 GDK_AVAILABLE_IN_ALL
+void            gtk_snapshot_append_conic_gradient      (GtkSnapshot            *snapshot,
+                                                         const graphene_rect_t  *bounds,
+                                                         const graphene_point_t *center,
+                                                         float                   rotation,
+                                                         const GskColorStop     *stops,
+                                                         gsize                   n_stops);
+GDK_AVAILABLE_IN_ALL
 void            gtk_snapshot_append_border              (GtkSnapshot            *snapshot,
                                                          const GskRoundedRect   *outline,
                                                          const float             border_width[4],